<?php
class AdCategory extends AppModel {

	public $name         = 'AdCategory';
    public $displayField = 'category';
    public $validate     = array(
        'parent' =>
            array(
                'minlength' => array('rule' => array('minLength', 1)),
                'maxlength' => array('rule' => array('maxLength', 50))
            ),
        'category' =>
            array(
                'minlength' => array('rule' => array('minLength', 1)),
                'maxlength' => array('rule' => array('maxLength', 50))
            )
    );

    public function afterSave () {
        $this->clearCache('element__categories', 'views', '');
    } // afterSave

    public function afterDelete () {
        //$this->clearCache('element__categories', 'views', '');
    } // afterDelete


    public function mainCategories () {
        $this->cacheQueries = true;
        $data = array();
        $ret  = $this->query('SELECT DISTINCT `parent` FROM `ad_categories` AS `'.$this->name.'`');

        foreach ($ret as $model) {
           $data[] = $model[$this->name]['parent'];
        }

        return $data;
    } // mainCategories
}
?>